{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Week 1 - Part 2. Downloading the ICESat 1 and 2."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebooks is for learning how to downlaod the ICESat series. This is created by Myung Sik Cho\n",
    "\n",
    "In order to do this exercise, you need to prepare these things:\n",
    "1.\tCreate an account on `Earthdata` (https://earthdata.nasa.gov/)\n",
    "2.\tCreate an account on `Github` (https://github.com/)\n",
    "3.\tDownload the `Anaconda` (https://www.anaconda.com/)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1) Manual way to download them\n",
    "\n",
    "This is a way to download the ICESat 1 and 2 via `NSIDC` (https://nsidc.org/data).\n",
    "\n",
    "Unfortunately, there is not package supporting to downlaod the ICESat1 via python, while the ICESat2 has the package named `icepyx` (https://icepyx.readthedocs.io/en/latest/).\n",
    "\n",
    "Here is the link for downloading them:\n",
    "\n",
    "ICESat 1: https://nsidc.org/data/glah14\n",
    "\n",
    "ICesat 2: https://nsidc.org/data/ATL13/versions/2\n",
    "\n",
    "Also, we can see the track using OpenAltimetry: https://openaltimetry.org/\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2) Using python\n",
    "\n",
    "To follow this exercise, you need to fetch this notebook file from Github.\n",
    "\n",
    "Open the Console.\n",
    "\n",
    "Set the directroy for fetching it using `cd`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Example\n",
    "cd ICESat_water_level"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Login your github's account\n",
    "git config --global user.name \"your_username\"\n",
    "git config --global user.email \"your_email_address@example.com\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Type it in console\n",
    "git clone https://github.com/choms516/ICESat_water_level.git"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Install the package"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Type it in console\n",
    "git clone https://github.com/icesat2py/icepyx.git"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Load the packages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from icepyx import icesat2data as ipd\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#### Product: Inland water\n",
    "atl_dt = 'ATL13'\n",
    "#### Tonlesap Lake (TSL)\n",
    "sp_ex = [103.643, 12.375, 104.667, 13.287]\n",
    "#### Date Range\n",
    "date_r = ['2019-06-01','2019-09-01']\n",
    "\n",
    "#### Access to ICESat2 Data\n",
    "tsl = ipd.Icesat2Data(atl_dt,sp_ex,date_r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Earthdata Login password:  ··········\n"
     ]
    }
   ],
   "source": [
    "## account info\n",
    "earthdata_uid = 'choms516'\n",
    "email = 'whaudtlr516@gmail.com'\n",
    "\n",
    "## log-in\n",
    "tsl.earthdata_login(earthdata_uid,email)\n",
    "## Then, we can type the password"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#### Set the direction download it\n",
    "cd 2020CGCEO_Workshop/  ### just example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total number of data order requests is  1  for  8  granules.\n",
      "Data request  1  of  1  is submitting to NSIDC\n",
      "order ID:  5000000724720\n",
      "Initial status of your order request at NSIDC is:  processing\n",
      "Your order status is still  processing  at NSIDC. Please continue waiting... this may take a few moments.\n",
      "Your order is: complete\n",
      "Beginning download of zipped output...\n",
      "Data request 5000000724720 of  1  order(s) is downloaded.\n",
      "Download complete\n"
     ]
    }
   ],
   "source": [
    "path = './download'\n",
    "\n",
    "tsl.download_granules(path,subset=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## By next time\n",
    "\n",
    "You have to download ICESat1's file by accessing NSIDC and ICESat2's file using python."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
